<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0,user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="format-detection" content="telephone=no">
    <title>发布房产信息</title>
    <link rel="stylesheet" href="{AMOUSE_HOUSE_RES}css/house.css?v=20150401"/>
    <link rel="stylesheet" href="{AMOUSE_HOUSE_RES}css/sweet-alert.css?v=20150401"/>
    <script src="{AMOUSE_HOUSE_RES}js/jquery.js?v=20140519"></script>
    <script src="{AMOUSE_HOUSE_RES}js/sweet-alert.min.js?V=20150514"></script>
    <script type="text/javascript">
        function checkdata(){
            var pic_url=document.getElementById('pic_url').value;
            var pic_url1=document.getElementById('pic_url1').value;
            var title=document.getElementById('title').value;
            var mobile=document.getElementById('mobile').value;
            var contacts=document.getElementById('contacts').value;
            var price=document.getElementById('price').value;
            var area=document.getElementById('area').value;
            var house_type=$("input[name='house_type']").val()
            var place=document.getElementById('place').value;
            var location_c=document.getElementById('location_c').value;
            var location_a=document.getElementById('location_a').value;
            var introduction=document.getElementById('introduction').value;
            var emp = /^\s*$/;
            if(emp.test(title)){
                sweetAlert("错误",'亲，请填写标题！', "error");
                return false;
            }/*else if(emp.test(pic_url1)){
                sweetAlert("错误",'亲，图片正在上传中，请稍候提交！', "error");
                return false;
            }else if(emp.test(pic_url)){
                sweetAlert("错误",'亲，图片正在上传中，请稍候提交！', "error");
                return false;
            }*/else if(emp.test(mobile)){
                sweetAlert("错误",'亲，请填写电话！', "error");
                return false;
            }else if(emp.test(contacts)){
                sweetAlert("错误",'亲，请填写联系人！', "error");
                return false;
            }else if(emp.test(price)){
                sweetAlert("错误",'亲，请填写每月总价！', "error");
                return false;
            }else if(emp.test(area)){
                sweetAlert("错误",'亲，请填写面积！', "error");
                return false;
            }else if(emp.test(house_type)){
                sweetAlert("错误",'亲，请填写户型如：两室两厅一厨一卫！', "error");
                return false;
            }else if(emp.test(location_c)||location_c==0){
                sweetAlert("错误",'亲，请选择市！', "error");
                return false;
            }else if(emp.test(location_a)||location_a==0){
                sweetAlert("错误",'亲，请选择区！', "error");
                return false;
            } else if(emp.test(introduction)){
                sweetAlert("错误",'亲，请填写房产介绍！', "error");
                return false;
            } else if(emp.test(place)){
                sweetAlert("错误",'亲，请填写房产地址！', "error");
                return false;
            }else{
                return true;
            }
        }

        function immediately(){
            var element = document.getElementById("place");
            if("\v"=="v") {
                element.onpropertychange = webChange;
            }else{
                element.addEventListener("input",webChange,false);
            }
        }
        var ii = 1;
        function webChange(){
            BodyOnLoad();
        }
        function BodyOnLoad() {
            var textarea= document.getElementById("place");
            textarea.style.posHeight=textarea.scrollHeight;
        }
    </script>
    <style>
        .m-form .row input[type='tel'], .m-form .row .time {
            width: 100%;
            height: 34px;
            padding: 0 12px;
            border: 1px solid #e1e1e1;
            background-color: #fff;
            outline: none;
            -webkit-box-shadow: none;
            box-shadow: none;
            -webkit-border-radius: 5px;
            border-radius: 5px;
        }
    </style>
</head>
<body>
<div class="app-view">
    <div class="app-page">
        <header class="app-head">
            <div class="inner">
                <a class="link app-back" href="javascript:history.back();">
                    <i class="icon-back"></i>
                </a>
                <p style=" float:right;"><a href="{php echo $this->createMobileUrl('index',array('type'=>$type))}" class=""><input type="button" value="首页" name="" style="color:#666; width:60px; height:28px;"/></a></p>
                <h1 class="title sliding">发布房产信息</h1>
            </div>
        </header>
        <section class="app-wrap">
            <div class="inner">
                <form class="m-form" id="fr1" name="fr1" onSubmit="return checkdata();" action="{php echo $this->createMobileUrl('new', array('wxid'=>$wxid));}" method="post">

                    <div class="row">
                        <span class="tag">标题：</span>
                        <input type="text" id="title" name="title" placeholder="请填写标题"/>
                    </div>
                    <div class="row">
                        <span class="tag">联系人：</span>
                        <input type="text" id="contacts" name="contacts" placeholder="请填写联系人"/>
                    </div>

                    <div class="row">
                        <span class="tag">联系电话：</span>
                        <input type="tel" id="mobile" name="phone" placeholder="请填写联系电话"/>
                    </div>

                    <div class="row">
                        <p><span class="tag">单价或总价：</span>
                          <input type="text" id="price" name="price" placeholder="请填写总价，单位：万元"/>
                        </p>
                        <p>&nbsp;</p>
                    </div>

                    <div class="row">
                        <span class="tag">面积：</span>
                        <input type="text" id="area" name="area" placeholder="请填写面积"/>
                    </div>

                    <div class="row">
                        <span class="tag">户型：</span>
                        <input type="text" id="house_type" name="house_type" placeholder="请填写户型 如：两室两厅一厨一卫"/>
                    </div>
                    
                    <div class="row">
                        <span class="tag">合作佣金：</span>
                        <input type="text" id="brokerage" name="brokerage" placeholder=""/>
                    </div>

                    <div class="row">
                        <span class="tag">楼层：</span>
                        <input type="text" id="floor" name="floor" placeholder="请输入楼层如：3楼/6楼"/>
                    </div>
                    <div class="row">
                        <span class="tag">详细描述：</span>
                        <textarea name="introduction" id="introduction"></textarea>
                    </div>

                    <div class="row">
                        <span class="tag">出售求购：</span>
                        <select name="type" style="height:34px; width:100%;">
                            <option value="0"> 出售 </option>
                            <option value="1"> 求购 </option>
                        </select>
                    </div>

                    <div class="row">
                        <span class="tag">图片1：</span>
                        <input type="file" id="file1" name="file" accept="image/*">
                        <input type='hidden' id='pic_url1' name='thumb1' value=" "/>
                        <label for="headUpload"><span id="img1"></span><img style="display:block" id="fileimg1" src="{AMOUSE_HOUSE_RES}images/home.png" width="120px;" class="hl-bdrs-16 fileimg"></label>
                    </div>
                    <div class="row">
                        <span class="tag">图片2：</span>
                        <input type="file" id="file" name="file" accept="image/*">
                        <input type='hidden' id='pic_url' name='thumb2' value=" "/>
                        <label for="headUpload"><span id="img2"></span>
                            <img id="fileimg" style="display:block" src="{AMOUSE_HOUSE_RES}images/home.png" width="120px;" class="hl-bdrs-16 fileimg"></label>
                    </div>
                    <div class="msg" style="margin-top:0; margin-bottom:0; margin-left:80px; color:red;">
                        建议图片为330px:220px
                    </div>
                    <div class="row">
                        <span class="tag">图片3：</span>
                        <input type="file" id="file2" name="file" accept="image/*">
                        <input type='hidden' id='pic_url2' name='thumb3' value=" "/>
                        <label for="headUpload"><span id="ccc"></span><img style="display:block" id="fileimg2" src="{AMOUSE_HOUSE_RES}images/home.png" width="120px;" class="hl-bdrs-16 fileimg"></label>
                    </div>

                    <div class="row">
                        <span class="tag">选择区域：</span>
                        <select name="location_p" id="location_p" style="height:34px; width:100%;"></select>
                        <select name="location_c" id="location_c" style="height:34px; width:100%;" ></select>
                        <select name="location_a" id="location_a" style="height:34px; width:100%;" ></select>
                        <script type="text/javascript" src="{AMOUSE_HOUSE_RES}js/region_select.js"></script>
                        <script type="text/javascript">
                            var location_p = "{if !empty($item['location_p'])}{$item['location_p']}{else}上海市{/if}";
                            var location_c = "{if !empty($item['location_c'])}{$item['location_c']}{else}市辖区{/if}";
                            var location_a = "{if !empty($item['location_a'])}{$item['location_a']}{else}徐汇区{/if}";
                            new PCAS("location_p", "location_c", "location_a", location_p, location_c, location_a);
                        </script>
                    </div>

                    <div class="row">
                        <span class="tag">房产地址：</span>
                        <textarea id="place" placeholder="输入地址快速搜索定位" name="place" data-rule-required="true" style="height:45px;width:95%;"/>{$item['place']}</textarea>
                        <!--<button style="position:relative;height:45px;background-color:RGB(62,175,14);top:-21px;" id="positioning" type="button" onclick="bmap.searchMapByAddress($('#place').val())"><font color="white" size="4px">搜索</font></button>-->
                    </div>
                    <style>
                        .m-form .row1 {
                            position: relative;
                            min-height: 34px;
                            margin-bottom: 6px;
                            padding-left: 0px;
                        }
                    </style>
                    <div class="row1">
                        <div id="l-map" style="overflow: hidden;display: none; position: relative; z-index: 0;
                        background-image: url(http://api.map.baidu.com/images/bg.png);width: 100%; height: 200px;margin-top: 10px; color: rgb(0, 0, 0); text-align: left;"></div>
						<span id="r-result">
							<input style="width:49%;"  type="hidden" id="lat" name="lat">
							<input style="width:49%;"  type="hidden" id="lng" name="lng">
						</span>
                        <div>
                            <input type="hidden" name="token" value="{$_W['token']}" />
                            <input class="submit" name="submit" id="sub1" type="submit" value="提交">
                </form>
            </div>
        </section>
    </div>
</div>
</body>

<script type="text/javascript" src="http://api.map.baidu.com/api?v=1.4"></script>
<script type="text/javascript" src="http://api.map.baidu.com/getscript?v=1.4&ak=&services=&t=20140102035142"></script>
<script type="text/javascript">
    $(function(){
        $(".location").change(function(){
            bmap.searchMapByPCD();
        });
    });

    var bmap = {
        'option' : {
            'lock' : false,
            'container' : 'l-map',
            'infoWindow' : {'width' : 250, 'height' : 100, 'title' : ''},
            'point' : {'lng' : "{if $item['lng']!='0.0000000000' && !empty($item['lng'])}{$item['lng']}{else}116.321328{/if}", 'lat' : "{if $item['lat']!='0.0000000000' && !empty($item['lat'])}{$item['lat']}{else}40.083793{/if}"}
        },
        'init' : function(option) {
            var $this = this;
            $this.option = $.extend({},$this.option,option);

            $this.option.defaultPoint = new BMap.Point($this.option.point.lng, $this.option.point.lat);
            $this.bgeo = new BMap.Geocoder();
            $this.bmap = new BMap.Map($this.option.container);
            $this.bmap.centerAndZoom($this.option.defaultPoint, 15);
            $this.bmap.enableScrollWheelZoom();
            $this.bmap.enableDragging();
            $this.bmap.enableContinuousZoom();
            $this.bmap.addControl(new BMap.NavigationControl());
            $this.bmap.addControl(new BMap.OverviewMapControl());
            //添加标注
            $this.marker = new BMap.Marker($this.option.defaultPoint);
            $this.marker.setLabel(new BMap.Label('请您移动此标记，选择您的坐标！', {'offset':new BMap.Size(10,-20)}));
            $this.marker.enableDragging();
            $this.bmap.addOverlay($this.marker);

            $this.showPointValue($this.marker.getPosition());
            //拖动地图事件
            $this.bmap.addEventListener("dragging", function() {
                $this.setMarkerCenter();
                $this.option.lock = false;
            });
            //缩入地图事件
            $this.bmap.addEventListener("zoomend", function() {
                $this.setMarkerCenter();
                $this.option.lock = false;
            });
            //拖动标记事件
            $this.marker.addEventListener("dragend", function (e) {
                $this.showPointValue();
                $this.showAddress();
                $this.bmap.panTo(new BMap.Point(e.point.lng, e.point.lat));
                $this.option.lock = false;
                $this.marker.setAnimation(null);
            });
        },
        'searchMapByAddress' : function(address) {
            var $this = this;
            $this.bgeo.getPoint(address, function (point) {
                if (point) {
                    $this.showPointValue();
                    $this.showAddress();
                    $this.bmap.panTo(point);
                    $this.setMarkerCenter();
                }
            });
        },
        'searchMapByPCD' : function(address) {
            var $this = this;
            $this.option.lock = true;
            $this.searchMapByAddress($('#location_p').val()+$('#location_c').val()+$('#location_a').val());
        },
        'setMarkerCenter' : function() {
            var $this = this;
            var center = $this.bmap.getCenter();
            $this.marker.setPosition(new BMap.Point(center.lng, center.lat));
            $this.showPointValue();
            $this.showAddress();
        },
        'showPointValue' : function() {
            var $this = this;
            var point = $this.marker.getPosition();
            $('#lng').val(point.lng);
            $('#lat').val(point.lat);
        },
        'showAddress' : function() {
            var $this = this;
            var point = $this.marker.getPosition();
            $this.bgeo.getLocation(point, function (s) {
                if (s) {
                    $('#place').val(s.address);
                    if (!$this.option.lock) {
                        new PCAS("location_p", "location_c", "location_a", s.addressComponents.province, s.addressComponents.city, s.addressComponents.district);
                    }
                }
            });
        }
    };
    $(function(){
        var option = {};
        bmap.init(option);
    });</script>
<script src="{AMOUSE_HOUSE_RES}js/zepto.min.js"></script>
<script type="text/javascript" src="{AMOUSE_HOUSE_RES}js/zepto.form.js"></script>
<script type="text/javascript">
    //图片上传
    var btn = $("body");
    $("#file").wrap('<form method="post" id="formUpload" action="{php echo $this->createMobileUrl('UploadImage');}" enctype="multipart/form-data"></form>');
    $("#file").change(function(){
        document.getElementById('fileimg').style.display = 'none';
        document.getElementById('img2').innerHTML = '正在上传，请耐心等候...';
        $("#formUpload").ajaxSubmit({
            dataType:  'json',
            beforeSend: function() {
            },
            uploadProgress: function(event, position, total, percentComplete) {
            },
            success: function(data) {

                if(data.error==1) {

                }else{
                    var pic_url = data.filename;
                    $('#fileimg').attr('src','{$_W['attachurl']}'+pic_url);
                    $('#pic_url').attr('value',pic_url);
                    document.getElementById('fileimg').style.display = 'block';
                    document.getElementById('img2').innerHTML = '';
                }
            },
            error:function(xhr){
                btn.html("上传失败了");
            }
        });
    });

    $("#file1").wrap('<form method="post" id="formUpload1" action="{php echo $this->createMobileUrl('UploadImage');}" enctype="multipart/form-data"></form>');
    $("#file1").change(function(){
        document.getElementById('fileimg1').style.display = 'none';
        document.getElementById('img1').innerHTML = '正在上传，请耐心等候...';
        $("#formUpload1").ajaxSubmit({
            dataType:  'json',
            beforeSend: function() {
            },
            uploadProgress: function(event, position, total, percentComplete) {

            },
            success: function(data) {
                if(data.error==1) {
                }else{
                    var pic_url = data.filename;
                    $('#fileimg1').attr('src','{$_W['attachurl']}'+pic_url);
                    $('#pic_url1').attr('value',pic_url);
                    document.getElementById('fileimg1').style.display = 'block';
                    document.getElementById('img1').innerHTML = '';
                }
            },
            error:function(xhr){
                btn.html("上传失败了");
            }
        });
    });


    $("#file2").wrap('<form method="post" id="formUpload2" action="{php echo $this->createMobileUrl('UploadImage');}" enctype="multipart/form-data"></form>');
    $("#file3").change(function(){
        document.getElementById('fileimg2').style.display = 'none';
        document.getElementById('img2').innerHTML = '正在上传，请耐心等候...';
        $("#formUpload2").ajaxSubmit({
            dataType:  'json',
            beforeSend: function() {
            },
            uploadProgress: function(event, position, total, percentComplete) {

            },
            success: function(data) {
                if(data.error==1) {
                }else{
                    var pic_url = data.filename;
                    $('#fileimg1').attr('src','{$_W['attachurl']}'+pic_url);
                    $('#pic_url1').attr('value',pic_url);
                    document.getElementById('fileimg2').style.display = 'block';
                    document.getElementById('img2').innerHTML = '';
                }
            },
            error:function(xhr){
                btn.html("上传失败了");
            }
        });
    });

</script>
</html>